package top.login;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import top.mapper.UserMapper;
import top.pojo.User;

import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Target;

public class Test {

    public static void main(String[] args) throws IOException {

        //1. 加载mybatis的核心配置文件，获取 SqlSessionFactory
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new
                SqlSessionFactoryBuilder().build(inputStream);

        //获取sqlSessionFactory对象,用他来执行sql
        SqlSession sqlSession = sqlSessionFactory.openSession();

        //执行sql

        //获取Mapper接口的代理对象
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        User lisi = userMapper.findUser("lisi", "222");
        System.out.println(lisi);

        //释放资源
        inputStream.close();
    }


}
